package com.zoweunion.mechanic.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.additional.query.impl.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;

import com.zoweunion.mechanic.dao.TSSsVehicleTypeDao;
import com.zoweunion.mechanic.entity.TSSsVehicleTypeEntity;
import com.zoweunion.mechanic.service.TSSsVehicleTypeService;


@Service("tSSsVehicleTypeService")
public class TSSsVehicleTypeServiceImpl extends ServiceImpl<TSSsVehicleTypeDao, TSSsVehicleTypeEntity> implements TSSsVehicleTypeService {

    @Autowired
    private TSSsVehicleTypeDao tSSsVehicleTypeDao;



    @Override
    public PageInfo queryPage(Map<String, Object> map)  {
        Integer pageSize = Integer.valueOf(map.get("pageSize").toString());
        Integer currentPage = Integer.valueOf(map.get("currentPage").toString());
        PageHelper.startPage(currentPage, pageSize);
        List<TSSsVehicleTypeEntity> mapList = tSSsVehicleTypeDao.queryPage(map);
        PageInfo<TSSsVehicleTypeEntity> mapPageInfo = new PageInfo<>(mapList);
        return mapPageInfo;
    }

    @Override
    public List<TSSsVehicleTypeEntity> tSSsVehicleTypeListFor(Map<String, Object> params) {

        LambdaQueryWrapper<TSSsVehicleTypeEntity> lambdaQuery =
                Wrappers.<TSSsVehicleTypeEntity>lambdaQuery();
        lambdaQuery.eq(true,TSSsVehicleTypeEntity::getParentId,"0");
        List<TSSsVehicleTypeEntity> typeEntities = tSSsVehicleTypeDao.selectList(lambdaQuery);
        typeEntities.forEach(item->{
            LambdaQueryWrapper<TSSsVehicleTypeEntity> lambdaQuery1 =
                    Wrappers.<TSSsVehicleTypeEntity>lambdaQuery();
            lambdaQuery1.eq(true,TSSsVehicleTypeEntity::getParentId,item.getId());
            item.setVehicleTypeEntities(tSSsVehicleTypeDao.selectList(lambdaQuery1));
        });
        return typeEntities;
    }

}